<?php
namespace app\front\controller\v2;

use app\front\controller\v2\BaseController;

class WithdrawController extends BaseController
{
    public function Withdraw(){
        $this->getWithdraworderService()->timedTaskPayForMember();
    }

    public function MemberWithdraw()
    {
        $WithdrawMoney = input("param.withdrawMoney");
        $persionCenterService = $this->getPersionCenterService();
        if (! $persionCenterService->checkIsMember()) {
            echo json_encode("亲 ,你还不是会员哦~\n请关注至富通公众号成为会员！");
        } else {
            if ($persionCenterService->getMemberTodayWithdrawNum() >= config('MemberWithdrawNum')) {
                echo json_encode("每日提现最多".config('MemberWithdrawNum')."次哦，请明天再试试吧！");
            } else {
                if ($WithdrawMoney < 1) {
                    echo json_encode("亲，提现金额最少为1元哦！");
                } else {
                    // 检查余额
                    $userMsg = $persionCenterService->checkResidue($WithdrawMoney);
                    $residue = $userMsg['residue'];
                    unset($userMsg['residue']);
                    if (! $userMsg) {
                        echo json_encode("钱包余额不足，提现失败！");
                    } else {
                        $withdraworderService = $this->getWithdraworderService();
                        $result = $withdraworderService->MemberWithdraw($userMsg, $WithdrawMoney);
                        $withdraworderService->insertWithdrawMember($userMsg, $result, $WithdrawMoney);
                        if (! is_array($result)) {
                            echo json_encode($result);
                        } else {
                            $persionCenterService->changeUserMoney($userMsg, $residue);
                            echo json_encode("提现成功,红包已发送至微信零钱！");
                        }
                    }
                }
            }
        }
    }
}

